package com.wms.mapper;

import com.wms.bean.Message;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MessageMapper {

    // 插入新消息
    @Insert("INSERT INTO messages (sender_id, sender_name, recipient, subject, content, urgent, send_time, reade, successe) " +
            "VALUES (#{senderId}, #{senderName}, #{recipient}, #{subject}, #{content}, #{urgent}, #{sendTime}, #{reade}, #{successe})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertMessage(Message message);

    // 根据收件人查询消息
    @Select("SELECT * FROM messages WHERE sender_name = #{sender_name} ORDER BY send_time DESC")
    List<Message> getMessagesByRecipient(String sender_name);

    // 根据ID查询消息
    @Select("SELECT * FROM messages WHERE id = #{id}")
    Message getMessageById(Long id);

    // 更新消息阅读状态
    @Update("UPDATE messages SET read = #{read} WHERE id = #{id}")
    int updateMessageReadStatus(Long id, Boolean read);
    // 根据发送者姓名查询消息
    @Select("SELECT * FROM messages WHERE sender_name = #{senderName} ORDER BY send_time DESC")
    List<Message> getMessagesBySenderName(String senderName);
}